<template>
  <page-main class="page-login page-login-account">
      <h3>广医云</h3>          
      <van-form>
        <van-field
            v-model="form.username"
            placeholder="输入账号"
            size="large"
            clearable
            left-icon="contact"
        >
        </van-field>
        <van-field
            style="margin-top:24px;"
            v-model="form.password"
            type="password"
            placeholder="输入密码"
            size="large"
            clearable
            left-icon="bag-o"
        >
        </van-field>
        <div style="margin: 46px 15px 0 15px;">
            <van-button type="info" round block @click="accountLogin">登 录</van-button>
        </div>
        </van-form>
        <van-submit-bar>
            <div class="agreement">
                <van-checkbox icon-size="16" checked-color="#1989fa" v-model="checked">已阅读并同意<span @click.stop="$refs.showAgreement.init('user')">《用户协议》</span></van-checkbox>
            </div>
        </van-submit-bar>
        <show-agreement ref="showAgreement" />
  </page-main>
</template>

<script>
import showAgreement from '@/components/ShowAgreement';
export default {
    data(){
        return{
            icon:{
                phone: '',
                password: '',
            },
            checked: true,
            form:{
                username: null,
                password: null,
                code: null,
                // uuid: null,
            }
        }
    },
    components:{
        showAgreement,
    },
    created(){
        this.form.code = this.$route.query.code;
    },
    methods:{
        verifyForm(){
            if(!this.$verify.null(this.form.username, '请输入账号')){
                return false;
            }
            if(!this.$verify.null(this.form.password, '请输入密码')){
                return false;
            }
            if(!this.checked){
                this.$toast('请先阅读并同意《用户协议》！');
                return false;
            }
            return true;
        },
        accountLogin(){
            if(!this.verifyForm()){
                return;
            }
            this.$http('post', '/login', this.form, (data,msg) => {  
                localStorage.setItem('agencyToken', data.data.token);
                this.$toast.success('登录成功！');
                this.$http('get', '/lgg/agency/info',{},(data,msg) => {
                    localStorage.setItem('userInfo', JSON.stringify(data.data));
                    if(data.data.wxBinding){ //判断是否已绑定微信
                        this.$store.commit('setUserInfo', data.data);
                        if(data.data.completeFlag == '0'){
                            this.$util.gotoPage('/');
                        }else{
                            this.$util.gotoPage('/user/perfect', data.data);
                        }
                    }else{
                        this.$util.gotoPage('/login/bind', this.form);
                    }
                });
            }, msg => {

            })            
        },

    }
}
</script>

<style>

</style>